package com.travel.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.qianfeng.util.ResultMsg;
import com.travel.entity.TbGateOrder;
import com.travel.entity.TbUser;
import com.travel.entity.TbView;
import com.travel.service.GateOrderService;
import com.travel.utils.ALiPayTools;
import com.travel.vo.payStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/gateOrder")
public class FontGateOrderController {

    @Autowired
    GateOrderService gateOrderService;
    /**
     * 添加景点门票订单(前端传对象)
     * */
    @GetMapping("/addOrderClass")
    public ResultMsg addOrderClass(TbUser user, TbView tbView){
        return gateOrderService.addOrderClass(user,tbView);
    }
// 查询所有的门票订单
//    @GetMapping("/addOrderClass")
//    public ResultMsg addOrderGetAll(TbUser user, TbView tbView){
//        return gateOrderService.addOrderClass(user,tbView);
//    }

    /**
     * 添加景点门票订单(前端传ID)
     * */
    @PostMapping("/addOrder")
    public ResultMsg addOrder(@RequestBody TbGateOrder tbGateOrder , HttpServletRequest req) throws AlipayApiException {
        ResultMsg tb = gateOrderService.addOrder(tbGateOrder,req);
        if (tb.getCode()==200){
            ALiPayTools.pay(tbGateOrder);
//            ALiPayTools.back(req);
            return ResultMsg.success();
        }
        return ResultMsg.error(201);
    }

    @GetMapping("/ordersubmitSuccess")
    public ResultMsg ordersubmitSuccess(){
        return gateOrderService.success();
    }
}
